package com.tigercel.xiangchengyun.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.tigercel.xiangchengyun.R;
import com.tigercel.xiangchengyun.entity.Banner;
import com.tigercel.xiangchengyun.ui.activities.BannerAdActivity;
import com.tigercel.xiangchengyun.ui.activities.WebViewActivity;
import com.tigercel.xiangchengyun.ui.custom.lbanners.LMBanners;
import com.tigercel.xiangchengyun.ui.custom.lbanners.adapter.LBaseAdapter;
import com.tigercel.xiangchengyun.utils.ImageLoaderUtils;

public class NewsBannerAdapter implements LBaseAdapter<Banner> {
    private Context mContext;

    public NewsBannerAdapter(Context context) {
        mContext = context;
    }

    @Override
    public View getView(final LMBanners lBanners, final Context context, int position, final Banner banner) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_news_banners, null);
        ImageView imageView = view.findViewById(R.id.id_image);
        ImageLoaderUtils.display(context, imageView, banner.getImgUrl()
                , R.mipmap.def_banner, R.mipmap.def_banner);

        final String name = banner.getName();
        final String htmlUrl = banner.getHtmlUrl();
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(mContext, BannerAdActivity.class);
                intent.putExtra("title", name);
                intent.putExtra("url", htmlUrl);
                intent.setClass(mContext, WebViewActivity.class);
                mContext.startActivity(intent);
            }
        });
        return view;
    }

}
